$(function () {
    //全局定义页数与总条数
    var markId = getUrlString('markid');
    var typeid = getUrlString('typeid');
    var page = -1,totalSize = 0;


    if(typeid === '0'){
        document.title="系统通知";
        $('.navName').html('系统通知')
    }else if(typeid === '1'){
        document.title="订单状态变更";
        $('.navName').html('订单状态变更')
    }else if(typeid === '2'){
        document.title="商品状态变更";
        $('.navName').html('商品状态变更')
    }else if(typeid === '3'){
        document.title="商品到期提醒";
        $('.navName').html('商品到期提醒')
    }else if(typeid === '4'){
        document.title="钱包到账通知";
        $('.navName').html('钱包到账通知')
    }else if(typeid === '5'){
        document.title="奖励与补偿";
        $('.navName').html('奖励与补偿')
    }
    var mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#messageList').empty();
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                getlist(page)
            }
        }
    });
    function getlist(page) {
        var data = {
            'markid':markId,
            'page':page,
            'typeid':typeid
        };
        getData('get','/niu/apiv3/noti_getlist.php',data,function (data) {
            console.log(data);
            var append = '';
            $(data.data).each(function () {
                let str;
                if (this.info.indexOf('排骨') !== -1) {
                     str = this.info.replace('排骨','蜜枣');
                }else if (this.info.indexOf('羊肉') !== -1) {
                    str = this.info.replace('羊肉','猪肉');
                }else if (this.info.indexOf('豆沙馅') !== -1) {
                    str = this.info.replace('豆沙馅','红豆');
                }else {
                    str = this.info
                }
                append += '<li>' +
                    '                    <div class="name">'+this.title+'</div>' +
                    '                    <div class="listContent">'+str+' ' ;
                    if(this.gotopage !== ''){
                        append += '<a style="color: #47BCFF;" href="'+this.gotopage+'">网页链接</a>';
                    }
                    append += '</div>' +
                    '                    <div class="time">'+subTime(this.time)+'</div>' +
                    '                </li>'
            });
            $('#messageList').append(append);

            totalSize = totalSize + 10;
            if (totalSize > data.datacount)
                mRefresh.endUpLoading(true);
            else{
                mRefresh.endUpLoading(false);
            }
        })
    }
    //标记已读
    function callback() {
        var data = {
            'markid':markId,
            'typeid':typeid
        };
        getData('post','/niu/apiv3/noti_callback.php',data,function (data) {
            console.log(data);
        })
    }
    callback();

    $('#goBack').click(function () {
        nativeCommand("dancool://activity=reflashfin")
    });
});
